//
//  RBCommonCenterAlterController.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/7.
//

#import "RBCommonCenterAlterController.h"

@interface RBCommonCenterAlterController ()
@property(strong,nonatomic)UIView *rbBgView;
@property(strong,nonatomic)UILabel *rbNameLabel;
@property(strong,nonatomic)UILabel *rbInfoLabel;
@property(strong,nonatomic)UIButton *rbCancleBtn;
@property(strong,nonatomic)UIButton *rbSureBtn;
@property(strong,nonatomic)UIView *rbMiddelView;
@property(strong,nonatomic)UIView *rbLineView;
@end

@implementation RBCommonCenterAlterController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor clearColor];
    [self rb_initViewUI];
    
    if (self.type == RBDSCommonAlertViewType_close) {
        self.rbNameLabel.text = self.titleLabStr;
        self.rbInfoLabel.text = self.contentLabStr;
    }
    
}
- (void)rb_initViewUI{
    
    [self.view addSubview:self.rbBgView];
    [self.rbBgView addSubview:self.rbNameLabel];
    [self.rbBgView addSubview:self.rbInfoLabel];
    [self.rbBgView addSubview:self.rbMiddelView];
    [self.rbBgView addSubview:self.rbCancleBtn];
    [self.rbBgView addSubview:self.rbSureBtn];
    [self.rbBgView addSubview:self.rbLineView];
    
    [self.rbBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(0);
    }];
    self.rbBgView.layer.cornerRadius = 10;
    self.rbBgView.layer.masksToBounds = YES;
    
    [self.rbNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(RBScaleWidth(25));
        make.centerX.mas_equalTo(0);
    }];
    [self.rbInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.rbNameLabel.mas_bottom).mas_offset(RBScaleWidth(10));
        make.centerX.mas_equalTo(0);
    }];
    [self.rbCancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(0);
        make.height.mas_equalTo(RBScaleWidth(48));
        make.width.mas_equalTo(RBScaleWidth(150));
    }];
    [self.rbLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.rbMiddelView.mas_bottom);
        make.left.mas_equalTo(self.rbCancleBtn.mas_right);
        make.centerX.mas_equalTo(0);
        make.height.mas_equalTo(RBScaleWidth(48));
        make.width.mas_equalTo(0.5);
    }];
    [self.rbSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(self.rbCancleBtn.mas_height);
        make.width.mas_equalTo(self.rbCancleBtn.mas_width);
    }];
    [self.rbMiddelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.rbSureBtn.mas_top);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    [self.view setNeedsLayout];
}

-(void)rbCancleBtnClicked:(UIButton *)sender{
    if (_leftBtnBlk) {
        self.leftBtnBlk();
    }
}
-(void)rbSureBtnClicked:(UIButton *)sender{
    if (_rightBtnBlk) {
        self.rightBtnBlk();
    }
}

- (UIView *)rbBgView{
    if(_rbBgView==nil){
        _rbBgView = [[UIView alloc] init];
        _rbBgView.backgroundColor = [UIColor whiteColor];
    }
    return _rbBgView;
}
-(UILabel *)rbNameLabel{
    if(_rbNameLabel==nil){
        _rbNameLabel = [UILabel rb_labelWithTitle:@"头部标题" color:RBColor(48, 50, 51) font:RBPingFangMediumFont(18) alignment:NSTextAlignmentCenter];
    }
    return _rbNameLabel;
}
-(UILabel *)rbInfoLabel{
    if(_rbInfoLabel==nil){
        _rbInfoLabel = [UILabel rb_labelWithTitle:@"副标题" color:RBColor(153, 153, 153) font:RBPingFangFont(14) alignment:NSTextAlignmentCenter];
    }
    return _rbInfoLabel;
}
- (UIButton *)rbCancleBtn{
    if(_rbCancleBtn==nil){
        _rbCancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rbCancleBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_rbCancleBtn setTitleColor:RBColor(51, 51, 51) forState:UIControlStateNormal];
        _rbCancleBtn.titleLabel.font = RBPingFangFont(15);
        _rbCancleBtn.backgroundColor = [UIColor whiteColor];
        [_rbCancleBtn addTarget:self action:@selector(rbCancleBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rbCancleBtn;
}
- (UIButton *)rbSureBtn{
    if(_rbSureBtn==nil){
        _rbSureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rbSureBtn setTitle:@"确认" forState:UIControlStateNormal];
        [_rbSureBtn setTitleColor:RBColor(242, 48, 48) forState:UIControlStateNormal];
        _rbSureBtn.titleLabel.font = RBPingFangFont(15);
        _rbSureBtn.backgroundColor = [UIColor whiteColor];
        [_rbSureBtn addTarget:self action:@selector(rbSureBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rbSureBtn;
}
- (UIView *)rbMiddelView{
    if(_rbMiddelView==nil){
        _rbMiddelView = [[UIView alloc] init];
        _rbMiddelView.backgroundColor = RBColor(237, 237, 237);
    }
    return _rbMiddelView;
}
- (UIView *)rbLineView{
    if(_rbLineView==nil){
        _rbLineView = [[UIView alloc] init];
        _rbLineView.backgroundColor = RBColor(237, 237, 237);
    }
    return _rbLineView;
}

@end
